﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YArchitech.Revit;

namespace YArchitech.Plumbing
{
	public class RectBeam
	{
		public RectBeam()
		{
		}

		public RectBeam(RectBeam src)
		{
			this.beams.AddRange(src.beams);
			this.beamParallelLeft = src.beamParallelLeft;
			this.beamVerticalDown = src.beamVerticalDown;
			this.beamParallelRight = src.beamParallelRight;
			this.beamVerticalUp = src.beamVerticalUp;
		}

		public bool IsAvailable()
		{
			return this.beams.Count >= 4 && this.beamParallelLeft != null && this.beamVerticalDown != null && this.beamParallelRight != null && this.beamVerticalUp != null;
		}

		public XYZ Min()
		{
			if (!this.IsAvailable())
			{
				return XYZ.Zero;
			}
			YJKLine hyline = new YJKLine(this.beamParallelLeft.SPoint, this.beamParallelLeft.EPoint);
			YJKLine hyline2 = new YJKLine(this.beamVerticalUp.SPoint, this.beamVerticalUp.EPoint);
			hyline.MakeUnBound();
			hyline2.MakeUnBound();
			return hyline.IntersectionPoint(hyline2.Line);
		}

		public XYZ Max()
		{
			if (!this.IsAvailable())
			{
				return XYZ.Zero;
			}
			YJKLine hyline = new YJKLine(this.beamVerticalDown.SPoint, this.beamVerticalDown.EPoint);
			YJKLine hyline2 = new YJKLine(this.beamParallelRight.SPoint, this.beamParallelRight.EPoint);
			hyline.MakeUnBound();
			hyline2.MakeUnBound();
			return hyline.IntersectionPoint(hyline2.Line);
		}

		public double Area()
		{
			if (!this.IsAvailable())
			{
				return 0.0;
			}
			XYZ xyz = this.Min();
			XYZ xyz2 = this.Max();
			return Math.Abs(xyz2.X - xyz.X) * Math.Abs(xyz2.Y - xyz.Y);
		}

		public List<BeamData> beams = new List<BeamData>();

		public BeamData beamParallelLeft;

		public BeamData beamVerticalDown;

		public BeamData beamParallelRight;

		public BeamData beamVerticalUp;
	}
}
